package org.codefinger.json.util.magic;

import java.lang.reflect.Field;

public interface MagicSetter {

	public void setValue(Object object, Object value);

	public static class MagicMethodSetter implements MagicSetter {

		private MagicMethod magicMethod;

		MagicMethodSetter(MagicMethod magicMethod) {
			this.magicMethod = magicMethod;
		}

		@Override
		public void setValue(Object object, Object value) {
			magicMethod.invoke(object, value);
		}

	}

	public static class FieldMagicSetter implements MagicSetter {

		private Field field;

		FieldMagicSetter(Field field) {
			field.setAccessible(true);
			this.field = field;
		}

		@Override
		public void setValue(Object object, Object value) {
			try {
				field.set(object, value);
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
	}

	public static class FinalFieldMagicSetter implements MagicSetter {

		@Override
		public void setValue(Object object, Object value) {

		}

	}

}
